#pragma once

#include "GUITreeNode.h"
#include "IGUIElement.h"
#include "Functor.h"

class GUITree : public IGUIElement
{
public:
	GUITree();
	
	void Paint();
	bool ReceiveEvent( IEvent& event );
	void Title( std::string& title );
	std::string Title() const;
	void Open( bool open );
	bool Open() const;
	void Font( std::string& font );
	void Font( HashedString& font );
	HashedString Font() const;
	void FontColor( unsigned int color );
	unsigned int FontColor() const;
	void Background( std::string& font );
	void Background( HashedString& font );
	HashedString Background() const;
	void OnChangeSelected( Pointer<Functor>& func );
	void OnDragDropSelected( Pointer<Functor>& func );

	Pointer<GUITreeNode>& Selected();
	void AddChildNode( Pointer<GUITreeNode>& child );
	Pointer<GUITreeNode> FindChildNode( GUITreeNode* child );	// Takes a while
	Pointer<GUITreeNode> FinalDropLocation();
	void RemoveChild( unsigned int index );
	void RemoveChild( GUITreeNode* child );
	GUITreeNode::Vector_t& Children();
protected:
	void DrawNode( GUITreeNode* node, Maths::Point<unsigned int>& drawLocation, int indent );
	bool ReceiveMouseUpEvent( Pointer<GUITreeNode>& node, Maths::Point<unsigned int>& location, Maths::Point<int>& click );
	bool ReceiveMouseDownEvent( Pointer<GUITreeNode>& node, Maths::Point<unsigned int>& location, Maths::Point<int>& click );
	
	Pointer<Functor> m_onChangeSelected;
	Pointer<Functor> m_onDragDropSelected;
	bool m_isOpen;
	bool m_dragging;
	HashedString m_background;
	HashedString m_font;
	unsigned int m_fontColor;
	std::string m_title;

	GUITreeNode::Vector_t m_nodes;
	Pointer<GUITreeNode> m_selected;
	Pointer<GUITreeNode> m_finalDropLocation;
};